
/**
 * @(#)FieldNotFoundException.java
 *
 * Copyright
 */
package com.radeonsys.litmus.data;

import org.springframework.core.NestedRuntimeException;

import java.text.MessageFormat;

/**
 * Thrown when an attempt is made to retrieve a reference to a field in a 
 * {@link Record} which does not exist.
 * 
 * @author Ranganath Kini (ranganathkini at gmail dot com)
 * @version 1.0
 */
public class FieldNotFoundException extends NestedRuntimeException {
	
	/**
	 * The generated serial version UID for this class
	 */
	private static final long serialVersionUID = 228375900961328323L;
	
	/**
	 * The error message to be used for this error
	 */
	private static final String ERROR_MESSAGE = "The field '{0}' was not found in this record.";
	
	/**
	 * Stores the name of the field causing this error
	 */
	private final String _fieldName;

	/**
	 * Creates a new instance of <code>FieldNotFoundException</code>
	 * 
	 * @param fieldName 	the name of the field which was not found
	 */
	public FieldNotFoundException(String fieldName) {
		super(MessageFormat.format(ERROR_MESSAGE, fieldName));
		_fieldName = fieldName;
	}

	/**
	 * Creates a new instance of <code>FieldNotFoundException</code>
	 * 
	 * @param fieldName		the name of the field which was not found
	 * @param cause			a reference to an instance of {@link Throwable} that
	 * 						represents the underlying cause of this error.
	 */
	public FieldNotFoundException(String fieldName, Throwable cause) {
		super(MessageFormat.format(ERROR_MESSAGE, fieldName), cause);
		_fieldName = fieldName;
	}

	/**
	 * Returns the name of the field causing this error
	 * 
	 * @return	the name of the field causing this error
	 */
	public String getFieldName() {
		return _fieldName;
	}
}
